package com.xqkad.myfile.tools;

import java.lang.reflect.*;

import android.app.Activity;
import android.os.Build;
import android.os.StatFs;
import android.os.storage.StorageManager;
import android.support.annotation.RequiresApi;

public class StorageList {
	private Activity mActivity;
	private StorageManager mStorageManager;
	private Method mMethodGetPaths;

	public StorageList(Activity activity) {
		mActivity = activity;
		if (mActivity != null) {
			mStorageManager = (StorageManager) mActivity.getSystemService(
					Activity.STORAGE_SERVICE);
			try {
				mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumePaths");
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			}
		}
	}
	public String[] getVolumePaths() {
		String[] paths = null;
		try {
			paths = (String[]) mMethodGetPaths.invoke(mStorageManager);
		} catch (Exception e) {} 
		return paths;
	}
	
	/**
	 * 
	 * @param path ·��
	 * @param i 0��Ч��С 1�ܴ�С
	 * @return �����ֽ���
	 */
	@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
	public static String getPathSize (String path, int i){
		StatFs sf = new StatFs(path);
		long blockSize = sf.getBlockSizeLong(); 
		long blockCount = sf.getBlockCountLong();// �ܴ�С
		long availableBlocks = sf.getAvailableBlocksLong(); // ��Ч��С
		long zsize = blockSize * blockCount ;
		long ysize = blockSize * availableBlocks ;
		if(i==0){
			return String.valueOf(ysize);// ��Ч��С
		}else{
			return String.valueOf(zsize);// �ܴ�С
		}
	}
}
